package com.nestease.qa.dao.api

import com.nestease.qa.dao.entity.Project
import com.nestease.qa.dao.params.ProjectQueryParams
import org.apache.ibatis.annotations.Insert
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update

/**
 * @author zoudongdong
 * @date 2018/2/28
 */
interface ProjectDAO {
    @Insert("""
            INSERT INTO `LG_project` (`projectId`, `teamId`, `projectName`, `ip`, `port`, `env`, `creator`, `lastEditor`,`status`)
            VALUES(#{projectId}, #{teamId}, #{projectName}, #{ip}, #{port}, #{env}, #{creator}, #{lastEditor},#{status});
            """)
    public void addProject(Project project);

    @Select("""
            select ifnull(max(projectId),0)
            from LG_project
            """)
    public int getMaxProjectId();

    @Select("""
            select *
            from LG_project
            where status=1
            """)
    public List<Project> getAllProject();

    @Select("""
            select *
            from LG_project
            where projectId=#{projectId}
            """)
    public Project getProjectDetail(int projectId);

    @Update("""
            update LG_project
            set teamId=#{teamId},projectName=#{projectName},ip=#{ip},port=#{port},env=#{env},lastEditor=#{lastEditor}
            where projectId=#{projectId}
            """)
    public void updateProject(Project project);

    @Update("""
            update LG_project
            set status=0,lastEditor=#{lastEditor}
            where projectId=#{projectId}
            """)
    public void deleteProject(Project project);

    @Select("""<script>
            select *
            from LG_project
            where 1=1
            <if test="teamId!=null">
            and teamId=#{teamId}
            </if>
            <if test="status!=null">
            and status=#{status}
            </if>
            </script>""")
    public List<Project> getProjectListInCondition(ProjectQueryParams params);

}
